import {Component} from 'react';
import http from '../utils/http';
class Child extends Component{
    render(){
        return(
            <div>
                <h1>使用封装的axios</h1>
                <button onClick={()=>this.getTop()}>获取排行榜</button>
                <button onClick={()=>this.getCart()}>获取购物车列表</button>
            </div>
        )
    }
    async getTop(){
        // let res = await http("/index/product/1/","get",{page:1,limit:10});
        // console.log(res)
        // 使用try catch捕获 async await错误
        try{
            let res = await http('/sendCode','post',{phone:15518835995});
            console.log(res)
        }catch(err){
            console.log(err)
        }
    }
    async getCart(){
        let res = await http(`/cart/list?page=1&limit=20&isValid=true`);
        console.log(res)
    }
}
export default Child;